package com.xinqi.modules.sys.gpt.controller.web;

import com.xinqi.common.base.response.R;
import com.xinqi.common.satoken.utils.LoginHelper;
import com.xinqi.modules.sys.gpt.dto.req.ChatMessageHistoryDTO;
import com.xinqi.modules.sys.gpt.dto.req.ChatMessageRemoveDTO;
import com.xinqi.modules.sys.gpt.dto.req.ChatMessageSendDTO;
import com.xinqi.modules.sys.gpt.dto.req.ChatMessageStopDTO;
import com.xinqi.modules.sys.gpt.dto.rsp.ChatMessageHistoryResultDTO;
import com.xinqi.modules.sys.gpt.dto.rsp.ChatMessageResultDTO;
import com.xinqi.modules.sys.gpt.service.ChatMessageService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * WEB -- 新奇AI消息
 *
 * @Author：yyzhen
 * @Package：com.xinqi.modules.sys.gpt.controller.app
 * @Project：XingqiClass-Cloud-Plus
 * @name：ChatMessageAppController
 * @Date：2023/5/29 11:06
 * @Filename：ChatMessageAppController
 */
@RestController
@RequestMapping("/web/message")
@RequiredArgsConstructor
public class ChatMessageWebController {

    private final ChatMessageService chatMessageService;

    @Operation(summary = "新奇AI消息 -- 发送")
    @PostMapping("/send")
    public R<ChatMessageResultDTO> sendMessage(@Validated @RequestBody ChatMessageSendDTO dto) {
        dto.setUserId(LoginHelper.getUserId().toString());
        return chatMessageService.sendMessage(dto);
    }


    @Operation(summary = "新奇AI消息 -- 历史记录")
    @PostMapping("/history")
    public R<ChatMessageHistoryResultDTO> historyMessage(@RequestBody ChatMessageHistoryDTO dto) {
        dto.setUserId(LoginHelper.getUserId().toString());
        return R.ok(chatMessageService.historyMessage(dto));
    }


    @Operation(summary = "新奇AI消息 -- 删除")
    @PostMapping("/remove")
    public R<Void> historyMessage(@Validated @RequestBody ChatMessageRemoveDTO dto) {
        dto.setUserId(LoginHelper.getUserId().toString());
        chatMessageService.removeMessage(dto);
        return R.ok();
    }


    @Operation(summary = "新奇AI消息 -- 结束")
    @PostMapping("/stop")
    public R<Void> stopMessage(@Validated @RequestBody ChatMessageStopDTO dto) {
        dto.setUserId(LoginHelper.getUserId().toString());
        chatMessageService.stopMessage(dto);
        return R.ok();
    }

}
